package com.youka.bussiness.controller.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import com.youka.bussiness.common.bean.RestResp;
import com.youka.bussiness.common.base.BaseEntity;
import com.youka.bussiness.common.base.BaseController;
import com.youka.bussiness.service.CouponRedemptionService;
import com.youka.bussiness.service.req.CouponRedemptionReqDto;
import com.youka.bussiness.service.req.CouponRedemptionUpdateDto;
import com.youka.bussiness.service.req.CouponRedemptionPageDto;
import com.youka.bussiness.service.res.CouponRedemptionDto;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.ArrayList;
import java.util.List;


import java.util.Map;

/**
 * 电子券核销记录表 Controller
 *
 * @author lfc
 * @date 2024-06-30 16:47:28
 */
@Api(tags = "web-电子券核销记录表")
@RestController()
@RequestMapping("/web/CouponRedemption")
public class CouponRedemptionController extends BaseController{

    @Autowired
    private CouponRedemptionService couponRedemptionService;

    /**
     * 查询电子券核销记录表详情
     */
    @ApiOperation(value = "获取电子券核销记录表详情")
    @PostMapping(value = "/single")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询电子券核销记录表详情", response = CouponRedemptionDto.class)
    })
    public RestResp findCouponRedemptionById(@RequestBody BaseEntity entity) {
        CouponRedemptionDto dto = couponRedemptionService.selectById(entity.getId());
        return success(dto);
    }

    /**
     * 查询电子券核销记录表集合
     */
    @ApiOperation(value = "查询电子券核销记录表集合")
    @PostMapping("/list")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询电子券核销记录表详情", response = CouponRedemptionDto.class)
    })
    public RestResp listCouponRedemption(@RequestBody CouponRedemptionReqDto couponRedemptionPageDto) {
        List<CouponRedemptionDto> list = couponRedemptionService.selectByList(couponRedemptionPageDto);
        return success().toAdminTree(list);
    }

    /**
     * 查询电子券核销记录表分页
     */
    @ApiOperation(value = "查询电子券核销记录表分页")
    @PostMapping("/page")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询电子券核销记录表详情", response = CouponRedemptionDto.class)
    })
    public RestResp pageCouponRedemption(@RequestBody CouponRedemptionPageDto couponRedemptionPageDto) {
        IPage<CouponRedemptionDto> page = couponRedemptionService.selectByPage(couponRedemptionPageDto);
        return success().toAdminPage(page);
    }

    /**
     * 新增电子券核销记录表
     */
    @ApiOperation(value = "新增电子券核销记录表")
    @PostMapping("/add")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询电子券核销记录表详情", response = RestResp.class)
    })
    public RestResp addCouponRedemption(@RequestBody CouponRedemptionReqDto couponRedemptionReqDto) {
        couponRedemptionService.insert(couponRedemptionReqDto);
        return success();
    }

    /**
     * 编辑电子券核销记录表
     */
    @ApiOperation(value = "编辑电子券核销记录表")
    @PostMapping("/update")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询电子券核销记录表详情", response = RestResp.class)
    })
    public RestResp updateCouponRedemption(@RequestBody CouponRedemptionUpdateDto couponRedemptionReqDto) {
        couponRedemptionService.update(couponRedemptionReqDto);
        return success();
    }

    /**
     * 删除电子券核销记录表主键
     */
    @ApiOperation(value = "删除电子券核销记录表")
    @PostMapping("/delete")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询电子券核销记录表详情", response = RestResp.class)
    })
    public RestResp delete(@RequestBody BaseEntity entity) {
        couponRedemptionService.deleteById(entity.getId());
        return success();
    }

}
